package jeons.use.home.action;

import javax.servlet.http.HttpServletRequest;



import jeons.Basket.dto.BasketDTO;
import jeons.admin.buildproduct.biz.BuildBiz;
import jeons.admin.buildproduct.dto.BuildQnADTO;
import jeons.admin.product.biz.ProductBiz;
import jeons.admin.product.dto.ProductSerchDTO;
import jeons.buildqna.biz.BuildQnaBiz;
import jeons.common.util.PageDTO;
import jeons.common.util.PagingHelper;
import jeons.use.home.biz.HomeBiz;

import org.springbyexample.web.servlet.view.tiles2.TilesUrlBasedViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/use/home")
public class HomeAction {
	@Autowired TilesUrlBasedViewResolver tilesUrlBasedViewResolver;
	@Autowired ProductBiz productBiz;
	@Autowired BuildBiz buildBiz;
	@Autowired HomeBiz homeBiz;
	@Autowired BuildQnaBiz buildQnaBiz;
	/** 
	* @Method Name  : Index 
	* @�ۼ���   : 2012. 1. 22. 
	* @�ۼ���   : Administrator 
	* @�����̷�  : ������ �ε���
	* @Method ���� : 
	* @return 
	*/
	@RequestMapping(value="/", method=RequestMethod.GET)
	public String index(Model model){
		tilesUrlBasedViewResolver.setTilesDefinitionName("default");
		model.addAttribute("data",buildBiz.getList());
		return "use/home/index";
	}
	
	@RequestMapping(value="/view", method=RequestMethod.GET)
	public String view(Model model,@RequestParam("bdno")int bdno,PageDTO pageDTO,BuildQnADTO buildQnADTO){
		tilesUrlBasedViewResolver.setTilesDefinitionName("default");
		System.out.println("Ȩ�������� ſ��");
		model.addAttribute("data", homeBiz.getData(bdno));
		
		ProductSerchDTO product_cpu_List = new ProductSerchDTO(10000,100000,"cpu");
		model.addAttribute("cpu",productBiz.getSerchTypeList(product_cpu_List));
		
		ProductSerchDTO product_memory_List = new ProductSerchDTO(10000,25000,"memory");
		model.addAttribute("memory",productBiz.getSerchTypeList(product_memory_List));
		
		ProductSerchDTO product_graphic_List = new ProductSerchDTO(10000,80000,"graphic");
		model.addAttribute("graphic",productBiz.getSerchTypeList(product_graphic_List));
		
		
		ProductSerchDTO product_cd_List = new ProductSerchDTO(10000,25000,"cd");
		model.addAttribute("cd",productBiz.getSerchTypeList(product_cd_List));
		
		
		ProductSerchDTO product_hard_List = new ProductSerchDTO(10000,100000,"hard");
		model.addAttribute("hard",productBiz.getSerchTypeList(product_hard_List));
		
		
		ProductSerchDTO product_power_List = new ProductSerchDTO(10000,25000,"power");
		model.addAttribute("power",productBiz.getSerchTypeList(product_power_List));
		
		
		ProductSerchDTO product_mainboard_List = new ProductSerchDTO(10000,76000,"mainboard");
		model.addAttribute("mainboard",productBiz.getSerchTypeList(product_mainboard_List));
		
		ProductSerchDTO product_case_List = new ProductSerchDTO(10000,25000,"case");
		model.addAttribute("case",productBiz.getSerchTypeList(product_case_List));
		
		ProductSerchDTO product_soundnlan_List = new ProductSerchDTO(10000,30000,"soundnlan");
		model.addAttribute("soundnlan",productBiz.getSerchTypeList(product_soundnlan_List));
		
		
		
		model.addAttribute("spk",productBiz.getTypeList("spk"));
		model.addAttribute("knm",productBiz.getTypeList("knm"));
		model.addAttribute("lcd",productBiz.getTypeList("lcd"));
		model.addAttribute("os",productBiz.getTypeList("os"));
		
		
		model.addAttribute("basket", new BasketDTO());
		
		
		
		buildQnADTO.setBdno(bdno);
		System.out.println("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd : "+bdno);
		System.out.println("aaaaaaaaaaaaaaaaaaa");
		int count = buildQnaBiz.getCount(buildQnADTO);
		model.addAttribute("count", count);
		model.addAttribute("qnadata", buildQnaBiz.getList(buildQnADTO));
		System.out.println("aaaaaaaaaaaaa");
		model.addAttribute("page",PagingHelper.instance.autoPaging(count, pageDTO.getPlRowRange(), pageDTO.getPlPageRange(), buildQnADTO.getPage()));
		return "use/home/view";
	}
}
